package com.hermes.biz.dao.message.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hermes.biz.common.model.message.MessageDO;
import com.hermes.biz.dao.message.MessageDAO;

public class MessageDAOImpl extends SqlMapClientDaoSupport  implements MessageDAO {
	
	private Logger log = Logger.getLogger(MessageDAOImpl.class);

	public MessageDO getMessageContenById(long messageId) {
		try {
			return (MessageDO) getSqlMapClientTemplate().
					getSqlMapClient().queryForList("MessageDAO.getMessageContenById", messageId);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<MessageDO> getMessageByItemId(long itemId) {
		try {
			return (List<MessageDO>) getSqlMapClientTemplate().
					getSqlMapClient().queryForList("MessageDAO.getMessageByItemId", itemId);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<MessageDO> getMessageByUserId(long userId) {
		try {
			return (List<MessageDO>) getSqlMapClientTemplate().
					getSqlMapClient().queryForList("MessageDAO.getMessageByUserId", userId);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;
	}

	public long saveMessage(MessageDO messageDO) {
		
		try {
			return (Long) this.getSqlMapClientTemplate().getSqlMapClient().insert("MessageDAO.saveMessage", messageDO);
		} catch (SQLException e) {
			log.error(e);
		}
		return 0;
	}

}
